package com.example.learningspringboot.mybatis.mapper;

import com.example.learningspringboot.mybatis.pojo.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface MybatisMapper {

    int createUser(User user);

    User findById(Integer id);

    List<User> findByIds(List<Integer> ids);

    int deleteUser(Integer id);

    // 这里我们使用了@Param注解来指定参数名称，这样在XML映射文件中可以更清晰地引用这些参数
    User findByNameAndCreateTime(@Param("name") String name, @Param("createTime") LocalDateTime createTime);

    // 3.4.2 使用注解方式定义结果映射
    @Results(id = "userResult", value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
    })
    @Select("select * from user where create_time = #{createTime}")
    User findByCreateTime(@Param("createTime") LocalDateTime createTime);

}
